package com.itheima.demo.my_set;

import java.util.Comparator;
import java.util.TreeSet;

public class SetTreeDemo02 {//按字符串的长短排序
    public static void main(String[] args) {
//        TreeSet<String> strings = new TreeSet<>(new Comparator<String>() {
//            @Override
//            public int compare(String o1, String o2) {
//                int result = o1.length() - o2.length();
//                result = result == 0 ?o1.compareTo(o2):result;
//                return  result;
//            }
//        });

        TreeSet<String> strings = new TreeSet<>(
                (String s1,String s2)->{
                    int result = s1.length() - s2.length();
                    result = result == 0 ?s1.compareTo(s2):result;
                    return result;
                }
        );

        strings.add("a");
        strings.add("aa");
        strings.add("b");
        strings.add("abb");

        System.out.println(strings);
    }
}
